From 34a7c32ea9f183e69ec47db171be8898f8a96623 Mon Sep 17 00:00:00 2001 From: "Karl O. Pinc" Date: Sun, 6 Dec 2020 13:12:11 -0600 Subject: [PATCH] A fixture that makes a real request object --- README.rst | 9 +++++++++ src/pgwui_testing/pytest_plugin.py | 21 +++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/README.rst b/README.rst index 7aba57f..41ecaf3 100644 --- a/README.rst +++ b/README.rst @@ -53,6 +53,15 @@ This makes the following fixtures available: Side Effects: pyramid.threadlocal.get_current_request() returns a Pyramid DummyRequest instance. + pyramid_real_request_config + Input: path, \*\*kwargs + + Is a (regular) Pyramid Configurator instance. + + Side Effects: pyramid.threadlocal.get_current_request() returns + a (regular) Pyramid Request instance, created with a call to + pyramid.request.Request.blank(path, \*\*kwargs). + pgwui__component_entry_point Input: A pgwui component name, as a string diff --git a/src/pgwui_testing/pytest_plugin.py b/src/pgwui_testing/pytest_plugin.py index 025e55d..ed4b75b 100644 --- a/src/pgwui_testing/pytest_plugin.py +++ b/src/pgwui_testing/pytest_plugin.py @@ -31,6 +31,8 @@ from pyramid.testing import ( from pgwui_testing import pytest_plugin_helpers +import pyramid.request + # Fixtures @@ -47,6 +49,25 @@ def pyramid_request_config(): tearDown() +@fixture +def pyramid_real_request_config(path, **kwargs): + '''Returns a Pyramid "testing" Configurator() instance. + + Input: + path An URL path + **kwargs Configuration for a WebOb environ and a Pyramid request + + When called with a path and kwargs, establishes a real Pyramid + Request() instance made available via + pyramid.threadlocal.get_current_request(). Calling the fixture + passes the fixture's arguments to a call to + pyramid.request.Request.blank(), to create the request. + ''' + request = pyramid.request.Request.blank(path, **kwargs) + yield setUp(request=request) + tearDown() + + @fixture def pgwui_component_entry_point(): '''Test that the supplied pgwui component is a pgui.components entry point -- 2.34.1